using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;

namespace CSDesktopUsiXMLRenderer
{

    class UsiXMLDocument
    {

        private String uiModelIdentifier = "uiModel";
        private String cuiModelIdentifier = "cuiModel";
        private String resourceModelIdentifier = "resourceModel";
        private String contextModelIdentifier = "contextModel";

        private XmlNode uiModel;
        private XmlNode cuiModel;
        private XmlNode resourceModel;
        private XmlNode contextModel;

        public UsiXMLDocument(String filePath)
        {
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read,
                                 FileShare.ReadWrite);
            
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(fs);

            uiModel = xmldoc.GetElementsByTagName(uiModelIdentifier).Item(0);
            cuiModel = xmldoc.GetElementsByTagName(cuiModelIdentifier).Item(0);
            resourceModel = xmldoc.GetElementsByTagName(resourceModelIdentifier).Item(0);
            contextModel = xmldoc.GetElementsByTagName(contextModelIdentifier).Item(0);
        }

        public XmlNode getCuiModel()
        {
            return this.cuiModel;
        }

        public XmlNode getResourceModel()
        {
            return this.resourceModel;
        }

        public XmlNode getContextModel()
        {
            return this.contextModel;
        }

        private void recurseElements(XmlNode node, int p)
        {
            String name = node.LocalName;

            for (int i = 0; i < p; i++)
            {
                Console.Write(" ");
            }
            Console.WriteLine(name);

            if (node.Attributes != null)
            {
                foreach (XmlAttribute att in node.Attributes)
                {
                    Console.Write(att.Value);
                }
            }

            foreach (XmlNode child in node.ChildNodes)
            {
                this.recurseElements(child, p+1);
            }


        }

        



    }
}


